<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
  <title>日志列表</title>
  <div th:replace="common/link::header"></div>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">类名称</label>
            <div class="layui-input-block">
              <input type="text" name="className" placeholder="请输入类名称" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">方法名称</label>
            <div class="layui-input-block">
              <input type="text" name="methodName" placeholder="请输入方法名称" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
            <button class="layui-btn layui-btn-primary" data-type="resetForm">重置</button>
          </div>
        </div>
      </div>
      <div class="layui-card-body">
        <table id="logTable" lay-filter="logTable"></table>
        <script type="text/html" id="tableBar">
          <a sec:authorize="hasAuthority('log:del')" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
      </div>
    </div>
  </div>
<div th:replace="common/script::footer"></div>
<script th:inline="javascript">
  layui.config({
      base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
      index: 'lib/index' //主入口模块
  }).use(['index', 'useradmin', 'table'], function() {
    let $ = layui.$,
            form = layui.form,
            table = layui.table;
      //监听搜索
      form.on('submit(search)', function(data){
        let field = data.field;
          //执行重载
          table.reload('logTable', {
              where: field
          });
      });
      // 查询列表接口
      table.render({
          elem: '#logTable'
          ,height: 'full-110'
          ,url:  ctx + '/sysLog/list'
          ,page: true //开启分页,
          ,limit: 10 // 多少条
          ,request: {
              pageName: 'pageNum', //页码的参数名称，默认：page
              limitName: 'pageSize' //每页数据量的参数名，默认：limit
          }
          ,parseData: function (result) {
              return {
                  "code": result.code,
                  "count": result.data.total,
                  "data": result.data.records
              }
          }
          ,response: {
              statusCode: 200 //成功的状态码，默认：0
          }
          ,cols: [[ //表头
              {field: 'id', title: 'ID', sort: true, width: 80, fixed: 'left'},
              {field: 'packageName', title: '包名称'},
              {field: 'className', title: '类名称'},
              {field: 'methodName', title: '方法名称'},
              {field: 'argsName', title: '参数名'},
              {field: 'argsValue', title: '参数值'},
              {field: 'exceptionName', title: '异常类型'},
              {field: 'errMsg', title: '错误信息'},
              {field: 'stackTrace', title: '异常堆栈信息'},
              {field: 'createTime', title: '创建时间'},
              {toolbar: '#tableBar', title: '操作', width: 300, align:'center',fixed: 'right'}
          ]]
      });
      table.on('tool(logTable)', function(obj){
        let data = obj.data //获得当前行数据
                ,layEvent = obj.event;
        if(layEvent === 'del'){
          active.del(data.id);
        }
      });
      $('.layui-btn').on('click', function(){
        let type = $(this).data('type');
        active[type] && active[type].call(this);
      });
      /* 触发弹层 */
      let active = {
        /**
         * 重置
         */
        resetForm: function () {
          $(".layui-form").find("input").val("");
          form.render();
          table.reload('logTable', {
            where: {
              className: "",
              methodName: ""
            }
          });
        },
        /**
         * 删除
         * @param id id
         */
        del: function(id){
          layer.confirm('真的删除行么', function(index){
            //向服务端发送删除指令
            $.ajax({
              type: 'DELETE',
              url:  ctx + '/sysLog/del/' + id,
              contentType:'application/json;charset=UTF-8',
              dataType: 'json',
              success: function(result) {
                layer.msg(result.message);
                if (result.code === 200) {
                  layer.close(index);
                  table.reload('logTable');
                }
              }
            });
          });
        }
      }
  });
</script>
</body>
</html>
